Public Class ctlDropDownButtons
    Inherits System.Windows.Forms.UserControl

    Private m_Expanded As Boolean = False
    Private m_Text As String = "DropDownButtons1"


    Const c_COLLAPSEDBASESIZE As Integer = 23
    Private c_DISABLEDBUTTONBACKCOLOR As Color = Color.DarkGray
    Private c_DISABLEDBUTTONFONTCOLOR As Color = Color.DimGray
    Private c_ENABLEDBUTTONBACKCOLOR As Color = Color.LightSkyBlue
    Private c_ENABLEDBUTTONFONTCOLOR As Color = Color.Black

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnMain As System.Windows.Forms.Button
    Friend WithEvents lstDropList As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnMain = New System.Windows.Forms.Button()
        Me.lstDropList = New System.Windows.Forms.ListBox()
        Me.SuspendLayout()
        '
        'btnMain
        '
        Me.btnMain.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnMain.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnMain.Name = "btnMain"
        Me.btnMain.TabIndex = 0
        Me.btnMain.Text = "Orders"
        '
        'lstDropList
        '
        Me.lstDropList.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left)
        Me.lstDropList.BackColor = System.Drawing.Color.LightSkyBlue
        Me.lstDropList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lstDropList.Location = New System.Drawing.Point(0, 24)
        Me.lstDropList.Name = "lstDropList"
        Me.lstDropList.Size = New System.Drawing.Size(75, 2)
        Me.lstDropList.TabIndex = 1
        '
        'ctlDropDownButtons
        '
        Me.BackColor = System.Drawing.Color.LightSkyBlue
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lstDropList, Me.btnMain})
        Me.ForeColor = System.Drawing.Color.Black
        Me.Name = "ctlDropDownButtons"
        Me.Size = New System.Drawing.Size(75, 24)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Expand()
        ' expands the control to the required size, but no bigger than the client... yeah
        Dim listSize As Int16 = lstDropList.ItemHeight * lstDropList.Items.Count

        If listSize < 10 Then listSize = 10

        Me.Height = c_COLLAPSEDBASESIZE + listSize

    End Sub

    Private Sub Collapse()
        ' collapses the control to show only the main button
        Me.Height = c_COLLAPSEDBASESIZE
    End Sub

    Public ReadOnly Property List() As ListBox
        Get
            Return Me.lstDropList
        End Get
    End Property

    Private Sub btnMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMain.Click

        If m_Expanded Then
            Collapse()
        Else
            Expand()
        End If
        m_Expanded = Not m_Expanded
    End Sub

    Public Overrides Property Text() As String
        Get
            Return btnMain.Text
        End Get
        Set(ByVal Value As String)
            btnMain.Text = Value
        End Set
    End Property

    Public Shadows Property Enabled() As Boolean
        Get
            Return btnMain.Enabled
        End Get
        Set(ByVal Value As Boolean)
            btnMain.Enabled = Value
            If btnMain.Enabled Then
                btnMain.BackColor = c_ENABLEDBUTTONBACKCOLOR
                btnMain.ForeColor = c_ENABLEDBUTTONFONTCOLOR
            Else
                btnMain.BackColor = c_DISABLEDBUTTONBACKCOLOR
                btnMain.ForeColor = c_DISABLEDBUTTONFONTCOLOR
            End If
        End Set
    End Property

End Class
